/*************************************************************************************************
 * @file api_gap.h
 * @author BLE GROUP ()
 * @brief 
 * @version 1.0.0
 * @date 2025-03-10
 * 
 * 
*************************************************************************************************/
#ifndef __API_BLE_STASCK_H__
#define __API_BLE_STASCK_H__

#include <stddef.h>
#include <stdarg.h>
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdio.h>
#include "addr.h"
#include "adv.h"
#include "conn.h"
#include "gatt.h"
#include "att.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "hci_core.h"
#include "sys_timeout.h"
#include "gap_def.h"
#include "uuid.h"
#include "gatt.h"


int ll_adv_reset(void);
void bt_buf_init_ext(void);
void bt_base_init(void (*bt_buf_init_lib)(void));
void VTIMER_Init(void);


void ble_set_adv_addr(uint8_t *addr);


void ble_set_adv_param(struct bt_hci_cp_le_set_adv_param *adv_param);


void ble_adv_enable(void);

void ble_adv_disable(void);

void ble_set_adv_data(const struct bt_data *adv_buf, uint32_t size);

void ble_set_scan_rsp_data(const struct bt_data *scan_rsp_buf, uint32_t size);

int ble_update_conn_param(uint32_t handle, uint16_t cnt_intvl_min, uint16_t cnt_intvl_max, uint16_t lt, uint16_t  cnt_to);

void ble_disconnect(uint32_t handle);


int ble_user_service_add(const void * p_svc);

void ble_event_callback(struct bt_conn_cb *cb);

void ble_host_init(void);

void ble_host_work_polling(void);

void ble_sleep_check(void);
#if 0

typedef void (* ble2g4_co_tx_end_cb)();
typedef void (* ble2g4_co_rx_end_cb)(uint8_t is_sync_it,uint8_t sync_ok, uint8_t crc_ok);


void ble_2g4_init(void);

//return val: 0 ok, 1 pre tx/rx not finished, 2 is not ble non-connectable adv data, 3 tx len is 0 or > 39 bytes
uint8_t ble_2g4_tx_data(uint8_t * tx_buf, uint8_t tx_len, uint8_t chl,ble2g4_co_tx_end_cb tx_end_cb);

//timeout: time to wait for sync ok, ms
//return val: 0 ok, 1 pre tx/rx not finished
uint8_t ble_2g4_rx_data(uint8_t * rx_buf, uint8_t chl,uint16_t timeout,ble2g4_co_rx_end_cb rx_end_cb);


void ble_2g4_tx_rx_stop(void);


uint8_t ble_2g4_is_idle(void);
#endif

int ble_get_rssi(void);

//int dbm: -25dbm ~ 12dbm
void ble_set_power(int dbm);

#endif